const DoublyLinkedList = require("../template.js")

/** 3. 删除方法测试 */
function testRemove() {
  const link = DoublyLinkedList.fromArray([1, 2, 3, 4])

  // 测试删除尾部
  link.removeTail()
  console.log("3.1 删除尾部:", link.tail.value === 3)

  // 测试删除头部
  link.removeHead()
  console.log("3.2 删除头部:", link.head.value === 2)

  // 测试按值删除
  link.append(5).append(6)
  link.removeByValue(5)
  console.log("3.3 按值删除:", link.size === 3 && link.tail.value === 6)

  // 测试按索引删除
  link.removeByIndex(1)
  console.log("3.4 按索引删除:", link.size === 2 && link.head.next.value === 6)

  // 测试清空链表
  link.clear()
  console.log(
    "3.5 删除空链表:",
    link.isEmpty() && link.head === null && link.tail === null
  )
  // 测试清空后操作
  link.append("a")
  console.log("3.6 清空后重新使用:", link.size === 1 && link.head === link.tail)
  console.log("--------------------")
}

testRemove()

module.exports = testRemove
